// 导入 fs 模块( File System )
const fs = require( 'fs' );

let name = '朱文杰' ;
let hometown = '庆阳' ;
let age = 18 ;
let married = false ;
const data = `大家好，我是${name}，我来自${hometown}，今年${age}岁，${married?'已婚':'未婚'}`;

let file = __dirname + '/message.txt' ;
let options = {
    encoding: 'UTF-8'
}

let cb = function(err){
    if( err ){
        console.log( '保存失败:' , err.message );
    }
}

fs.writeFile( file , data , options , cb );